﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="page-container">
    <div class="page-content">

        <div class="titlePanel">
            <div class="title-search">
                <table>
                    <tr>
                        <td style="padding-left: 2px;">
                            <input id="txt_keyword" type="text" class="form-control" placeholder="请输入要查询的关键字" style="width: 200px;" />
                        </td>
                        <td style="padding-left: 5px;">
                            <a id="btn_search" class="btn btn-primary btn-sm"><i class="fa fa-search"></i>&nbsp;查询</a>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="toolbar">
                <div class="btn-group">
                    <a id="replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                    <a id="add" authorize="yes" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                    <a id="edit" authorize="yes" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                    <a id="delete" authorize="yes" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                </div>
                <script>$('.toolbar').authorizeButton();</script>
            </div>
        </div>
        <div class="gridPanel">
            <table id="gridTable"></table>
        </div>
    </div>
</div>
<script>
    $(function () {
        gridTable();
    })
    function gridTable() {
        var $gridTable = $("#gridTable");
        $gridTable.jqGridEx({
            url: "/SystemSecurity/FilterIP/GetGridJson",
            height: $(window).height() - 96,
            colModel: [
                { label: "主键", name: "Id", hidden: true, key: true },
                {
                    label: '策略类型', name: 'Type', width: 80, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == true) {
                            return '<span class=\"label label-success\">允许访问</span>';
                        } else if (cellvalue == false) {
                            return '<span class=\"label label-default\">拒绝访问</span>';
                        }
                    }
                },
                { label: '起始IP', name: 'StartIP', width: 200, align: 'left' },
                { label: '结束IP', name: 'EndIP', width: 200, align: 'left' },
                //{ label: '创建人员', name: 'CreatorUserId', width: 100, align: 'left' },
                {
                    label: '创建时间', name: 'CreatorTime', width: 120, align: 'left',
                    formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i', newformat: 'Y-m-d H:i' }
                },
                { label: '备注', name: 'Description', width: 300, align: 'left' }
            ]
        });
        $("#btn_search").click(function () {
            $gridTable.jqGrid('setGridParam', {
                postData: { keyword: $("#txt_keyword").val() },
            }).trigger('reloadGrid');
        });
    }
    function btn_add() {
        $.fn.modalOpen({
            id: "Form",
            title: "新建策略",
            url: "/SystemSecurity/FilterIP/Form",
            width: "450px",
            height: "400px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            $.fn.modalOpen({
                id: "Details",
                title: "查看策略",
                url: "/SystemSecurity/FilterIP/Form?keyValue=" + keyValue,
                width: "450px",
                height: "400px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
    }
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            $.fn.deleteForm({
                url: "/SystemSecurity/FilterIP/DeleteForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        }
    }
    function btn_details() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            $.fn.modalOpen({
                id: "Details",
                title: "查看策略",
                url: "/SystemSecurity/FilterIP/Details?keyValue=" + keyValue,
                width: "450px",
                height: "520px",
                btn: null,
            });
        }
    }
</script>
